<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<script type="text/javascript" src="/simple-check/js/checkbix.min.js"></script>
<link rel="stylesheet" href="/simple-check/css/checkbix.min.css">

<body class="easyui-layout">
<!-- 说明 字符串：Customer，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
	<!-- 主表  -->
	<table id="statistics_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="rownumbers:true, singleSelect:true,url:'/statics-list',
					  method:'get',
					  toolbar:'#tb',
					  rowStyler:function(rowIndex,rowData){
					    if(rowIndex%2==1){
					        return 'background-color:#d9d9c2;';
					    }
					  },
					  loadMsg : '数据加载中',
					  fitColumns: true,
					  showFooter: true" >
        <thead>
        <tr>
            <th data-options="field:'tare',width:80,align:'center'">皮重</th>
            <th data-options="field:'grossWeight',width:80,align:'center'">毛重</th>
            <th data-options="field:'suttle',width:80,align:'center'">净重</th>
            <th data-options="field:'car_id',width:80,align:'center'">车号</th>
            <th data-options="field:'material_name',width:80,align:'center'">物料</th>
            <th data-options="field:'supplier_name',width:80,align:'center'">供方</th>
            <th data-options="field:'customer_name',width:80,align:'center'">收方</th>
            <#--<th data-options="field:'tareP',width:80,align:'center'">司磅员</th>-->
            <th data-options="field:'create_time',width:80,align:'center'">时间</th>
        </tr>
        </thead>
	</table>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
    <div>
        开始时间: <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" id="from" style="width:120px">
        结束时间: <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" id="to" style="width:120px" >
        选择车号:
        <input class="easyui-combobox" name="carIdSelect"id="carIdSelect"
               data-options="
				url : '/car-combobox-list',
				method: 'get',
				valueField:'value',
				textField:'text',
				">
        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-print" id="print">打印</a>
    </div>
    <div style="margin:5px 0;"></div>
	<div>
        <form id="ff">
            <div style="margin-bottom:20px">
				<table>
					<tr>
                        <td><input id="carId" name="carId" type="checkbox" class="checkbix" data-text="车号" value="car_id"></td>
                        <td><input id="materialName" name="materialName" type="checkbox" class="checkbix" data-text="物料" value="material_name" ></td>
                        <td><input id="supplierName" name="supplierName" type="checkbox" class="checkbix" data-text="供方" value="supplier_name" ></td>
                        <td><input id="customerName" name="customerName" type="checkbox" class="checkbix" data-text="收方" value="customer_name" ></td>
                        <td><input id="createTime" name="createTime" type="checkbox" class="checkbix" data-text="采集时间" value="create_time" ></td>
                        <#--<td><input id="tareP" name="tareP" type="checkbox" class="checkbix" data-text="司磅员" value="tareP采集" ></td>-->
					</tr>
				</table>
            </div>
        </form>
	</div>
    <div style="margin:5px 0;"></div>
</div>

<script>
    Checkbix.init();
</script>
<script type="text/javascript">
    var field = [];
    $('#carId').change(function(){
        search();
    });
    $('#materialName').change(function(){
        search();
    });
    $('#supplierName').change(function(){
        search();
    });
    $('#customerName').change(function(){
        search();
    });
    $('#createTime').change(function(){
        search();
    });


   $('#print').click(function(){

   })

    function search(){
        var carIdCheck = $('#carId').is(':checked');
        var carContent = $('#carId').val();
        var carIndex = $.inArray(carContent, field);

        var materialNameCheck = $('#materialName').is(':checked');
        var materialContent = $('#materialName').val();
        var materialIndex = $.inArray(materialContent, field);

        var supplierNameCheck = $('#supplierName').is(':checked');
        var supplierContent = $('#supplierName').val();
        var supplierIndex = $.inArray(supplierContent, field);

        var customerNameCheck = $('#customerName').is(':checked');
        var customerContent = $('#customerName').val();
        var customerIndex = $.inArray(customerContent, field);

        var createTimeCheck = $('#createTime').is(':checked');
        var createTimeContent = $('#createTime').val();
        var createTimeIndex = $.inArray(createTimeContent, field);

        if(carIdCheck){
            if(carIndex<0){
                field.push(carContent);
            }
        }else if(!carIdCheck){
            if(carIndex>=0){
                field.splice(carIndex,1)
            }
        }
        if(materialNameCheck){
            if(materialIndex<0) {
                field.push(materialContent);
            }
        }else if(!materialNameCheck){
            if(materialIndex>=0){
                field.splice(materialIndex,1)
            }
        }
        if(supplierNameCheck){
            if(supplierIndex<0) {
                field.push(supplierContent);
            }
        }else if(!supplierNameCheck){
            if(supplierIndex>=0) {
                field.splice(supplierIndex,1);
            }
        }
        if(customerNameCheck){
            if(customerIndex<0) {
                field.push(customerContent);
            }
        }else if(!customerNameCheck){
            if(customerIndex>=0) {
                field.splice(customerIndex,1);
            }
        }
         if(createTimeCheck){
            if(createTimeIndex<0) {
                field.push(createTimeContent);
            }
        }else if(!createTimeCheck){
            if(createTimeIndex>=0) {
                field.splice(createTimeContent,1);
            }
        }
        var param = field.join('@');
        var from = $('#from').val();
        var to = $('#to').val();
        var handler = '/statics-list?param='+param+'&carId=&from='+from+"&to="+to;
        $('#statistics_table').datagrid('options').url = handler;
        $('#statistics_table').datagrid('reload');
    }
</script>

<script type="text/javascript">
    function dateformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
    }
    function dateparser(s){
        if (!s) return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }
</script>
<script type="text/javascript">

    $('#searchByParameter').click(function () {
        var from = $('#from').val();
        var to = $('#to').val();
        var carId = $('#carIdSelect').val();
        var param = field.join('@');
        var handler = '/statics-list?param='+param+'&carId='+carId+"&from="+from+"&to="+to;
        $('#statistics_table').datagrid('options').url = handler;
        $('#statistics_table').datagrid('reload');
    });
</script>
